﻿
var page = {

    /* 此方法在第一次显示窗体前发生 */
    onLoad: function (event) {

        this.setData({ btn_title: { norImg: 'book_of.png' } });
        this.setData({
            Clock1: {
                hour: { x: 7, y: 53 },
                minute: { x: 5, y: 64 },
                second: { x: 3, y: 77 },
            }
        })
    },

    /* 此方法展示窗体后发生 */
    onResume: function (event) {

    },

    /* 当前页状态变化为显示时触发 */
    onShow: function (event) {
        console.dir(event)
        this.setData({ card_main: 0 });
        this.setData({
            card1: {
                card: {
                    page: this
                }
            }
        });
    },

    /* 当前页状态变化为隐藏时触发 */
    onHide: function (event) {

    },

    /* 此方法关闭窗体前发生 */
    onExit: function (event) {
        clearInterval(this.timer);//清除定时器
    },

    timer: 0,//定时器    
    time: 0, //时间，秒数

    onclick: function (event) {
        var that = this;
        switch (event.target.id) {
            case "btn_title":
                console.log('btn_1')
                this.setData({ main_card: 0 });
                this.setData({ btn_title: { norImg: 'book_of.png' } });
                this.setData({ btn_photo: { norImg: 'photo_on.png' } });
                this.setData({ btn_my: { norImg: 'alarm_on.png' } });
                break;
            case "btn_photo":
                console.log('btn_2')
                this.setData({ main_card: 1 });
                this.setData({ btn_title: { norImg: 'book_on.png' } });
                this.setData({ btn_photo: { norImg: 'photo_of.png' } });
                this.setData({ btn_my: { norImg: 'alarm_on.png' } });
                break;
            case "btn_my":
                console.log('btn_3')
                this.setData({ main_card: 2 });
                this.setData({ btn_title: { norImg: 'book_on.png' } });
                this.setData({ btn_photo: { norImg: 'photo_on.png' } });
                this.setData({ btn_my: { norImg: 'alarm_off.png' } });
                break;
            case "btn_stime":
                console.log('btn_stime')
                that.timer = setInterval(function () {
                    that.setData({ Clock1: { value: that.time } });
                    that.time++;
                    if (that.time > 60) {
                        /*更新完成的文本提示，清除定时器*/
                        that.setData({ label1: { value: "Time's up !!!" } });
                    } else {
                        /*更新progressbar的进度和label的显示文本*/
                        that.setData({ label1: { value: "Time: " + that.time + "%" } });
                        that.setData({ progressbar1: { value: that.time } });
                        that.progress++;
                    }
                }, 1000)
                break;
            case "btn_sptime":
                console.log('btn_sptime')
                clearInterval(that.timer);
                break;
            case "btn_retime":
                console.log('btn_retime')
                that.time = 0
                that.setData({ Clock1: { value: that.time } });
                that.setData({ label1: { value: "Time: " + that.time + "%" } });
                that.setData({ progressbar1: { value: that.time } });
                break;
        }
    },

    card_change: function (event) {
        console.dir(event)
        if ("change" == event.type) {
            switch (event.detail.value) {
                case 0:
                    this.setData({ btn_title: { norImg: 'book_of.png' } });
                    this.setData({ btn_photo: { norImg: 'photo_on.png' } });
                    this.setData({ btn_my: { norImg: 'alarm_on.png' } });
                    break;
                case 1:
                    this.setData({ btn_title: { norImg: 'book_on.png' } });
                    this.setData({ btn_photo: { norImg: 'photo_of.png' } });
                    this.setData({ btn_my: { norImg: 'alarm_on.png' } });
                    break;
                case 2:
                    this.setData({ btn_title: { norImg: 'book_on.png' } });
                    this.setData({ btn_photo: { norImg: 'photo_on.png' } });
                    this.setData({ btn_my: { norImg: 'alarm_off.png' } });
                    break;
            }
        }
    },

    image_change: function (event) {
        this.setData({
            DotIndicator1: {
                value: event.detail.value
            }
        })
    },
};

Page(page);

page = 0;
